package sale.wxb.loveshopping.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import sale.wxb.loveshopping.entity.model.SysUser;

import java.util.Collection;

public class UserDetailEntity implements UserDetails {
    private final SysUser user;
    private boolean expired = true;
    private boolean notLocked = true;

    public UserDetailEntity(SysUser sysUser) {
        this.user = sysUser;
    }

    public UserDetailEntity(SysUser sysUser, boolean isNotLocked) {
        this.user = sysUser;
        this.notLocked = isNotLocked;
    }

    public SysUser getUser() {
        return user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    /**
     * 是否未过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return expired;
    }

    /**
     * 设置是否未过期
     * @param flag flag
     */
    public void setExpired(boolean flag) {
        expired = !flag;
    };

    /**
     * 账号是否未锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        return this.notLocked;
    }

    /**
     * 密码是否未过期 一般没这个需求
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 获取账号是否启用
     */
    @Override
    public boolean isEnabled() {
        return user.getEnabled();
    }
}
